﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Net.Mail;
using System.Web.Configuration;
using ServeNHL.Models;



namespace ServeNHL.Helpers
{
    public class Email
    {
      

        public void sendEmail(string to, string subject, string message, string headers = "")
        {
            
            if (!Boolean.Parse(WebConfigurationManager.AppSettings["ServeNHL.Disable.Email"]))
            {
                try
                {
                    MailMessage msg = new MailMessage(WebConfigurationManager.AppSettings["ServeNHL.Test.Email.Address"], to);
                    msg.BodyTransferEncoding = System.Net.Mime.TransferEncoding.QuotedPrintable;
                    msg.Subject = subject;
                    msg.Body = message;
                    msg.IsBodyHtml = true;

                    SmtpClient client = new SmtpClient("localhost");
                    client.Port = 25;//Int32.Parse(WebConfigurationManager.AppSettings["ServeNHL.Email.Port"]);
                   // client.DeliveryMethod = SmtpDeliveryMethod.Network;
                    client.UseDefaultCredentials = false;
                    //client.Host = WebConfigurationManager.AppSettings["ServeNHL.Email.Server"];

                    client.Send(msg);
                }
                catch (Exception e)
                {
                    string errorMessage = "Error attempting to send email to " + to + ". \nThe email message trying to be sent is: "
                                          + message + "\n\nError Message: \n" + e.ToString();
                   
                }
            }
        }           // end of public void sendEmail(string to, string subject, string message, string headers = "")

       
    }               // end of public class Email
}                   // end of namespace 